package com.stars.pao.aicloud.controller;

import com.stars.pao.aicloud.entity.Comment;
import com.stars.pao.aicloud.service.ICommentService;
import com.stars.pao.aicloud.util.ResponseEntity;
import com.stars.pao.aicloud.util.SecurityUtil;
import com.stars.pao.aicloud.util.idempotent.Idempotent;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Tag(name = "评论控制器")
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Resource
    private ICommentService commentService;
//    实现自定义注解
    @Idempotent
    @PostMapping("/add")
    public ResponseEntity addComment(@Validated Comment comment){
        comment.setUid(SecurityUtil.getCurrentUser().getUid());
        boolean addResult = commentService.save(comment);
        if(addResult) {
           return ResponseEntity.succ(addResult);
        }
        return ResponseEntity.fail("数据保存失败，请重试");
    }

}
